<%
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<% js_env :CAN_READ => can_do(@context, @current_user, :read) %>
<% js_env :SYLLABUS_BODY => user_content(@syllabus_body || '') %>
<% @active_tab = "syllabus" %>
<% course_home ||= false %>
<div class="ic-Action-header">
  <div class="ic-Action-header__Primary">
  <% if course_home %>
    <h2 class="ic-Action-header__Heading"><%= @context.nickname_for(@current_user) %></h2>
  <% else %>
    <h1 class="ic-Action-header__Heading"><%= t 'titles.course_syllabus', "Course Syllabus" %></h1>
  <% end %>
  </div>
  <div class="ic-Action-header__Secondary">
    <a href="#" class="jump_to_today_link"><%= t 'links.jump_to_today', "Jump to Today" %></a>
  <% if can_do(@context, @current_user, :manage_content) %>
    <a href="#" class="edit_syllabus_link btn button-sidebar-wide">{{> icons/edit}} <%= t 'links.edit_syllabus_description', "Edit" %></a>
  <% end %>
  </div>
</div>

<div id="course_syllabus" style="margin-bottom: 10px;" class="user_content">
  <%= user_content(@syllabus_body) %>
</div>
<div id="course_syllabus_details" style="<%= hidden unless can_do(@context, @current_user, :manage_content) && (!@context.syllabus_body || @context.syllabus_body.strip.empty?) %>">
  <%= mt 'instructions.syllabus', <<-DOC
The syllabus page shows a table-oriented view of the course schedule, and the basics of
course grading.  You can add any other comments, notes, or thoughts you have about the course
structure, course policies or anything else.

To add some comments, click the "Edit" link at the top.
DOC
      %>
</div>
<%= form_for @context.class.to_s.underscore.to_sym, :url => context_url(@context, :context_url), :html => {:id => 'edit_course_syllabus_form', :style => 'display: none; margin-bottom: 10px;', :method => :put} do |f| %>
  <div style="float: right;">
    <a href="#" class="toggle_views_link toggle_html_editor_link"><%= t '#editor.switch_editor_html', "HTML Editor" %></a>
    <a href="#" class="toggle_views_link toggle_rich_editor_link" style="display:none;"><%= t '#editor.switch_editor_rich_text', "Rich Content Editor" %></a>
  </div>
  <%= f.blabel :syllabus_body, :en => "Syllabus Description" %>
  <div class="clear"></div>
  <%= f.text_area :syllabus_body, :style => "width: 100%; height: 300px;", :id => "course_syllabus_body" %>
  <div class='form-actions'>
    <button type="button" class="btn cancel_button"><%= t '#buttons.cancel', "Cancel" %></button>
    <button type="submit" class='btn btn-primary'><%= t 'buttons.update_syllabus', "Update Syllabus" %></button>
  </div>
<% end %>

<h2><%= before_label :assignments_summary, "Course Summary" %></h2>

<div id="syllabusContainer">
  <div id="syllabus_links">
    <a id="toggle_special_dates_in_syllabus">&nbsp;</a>
  </div>
  <% css_bundle("syllabus") %>
  <table id="syllabus" class="ic-Table--condensed">
    <thead>
      <tr>
        <th scope="col" style="width: 25%;"><%= t 'headers.date', "Date" %></th>
        <th scope="col" style="width: 75%;"><%= t 'headers.details', "Details" %></th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td scope="row">
          <span id="loading_indicator"/>
        </td>
      </tr>
    </tbody>
  </table>
</div>
